package com.huazai.yangge.interrupt;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 证明终端没有停止线程
 *
 * @author huazai
 * @date 2024/2/23
 */
public class InterruptDemo2 {
    static volatile boolean isStop = false;
    static AtomicBoolean atomicBoolean = new AtomicBoolean(false);

    public static void main(String[] args) throws InterruptedException {

        final Thread thread = new Thread(() ->
        {
            for (int i = 0; i < 300; i++) {
                System.out.println("i = " + i);
            }
            System.out.println("thread调用interrupt中断标识 = " + Thread.currentThread().isInterrupted());
        }, "t1");
        thread.start();

        System.out.println("thread默认中断标识 = " + thread.isInterrupted());

        TimeUnit.MILLISECONDS.sleep(2);

        thread.interrupt();
        System.out.println("thread中断后= " + thread.isInterrupted());

    }
}


